<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>审计档案归档明细统计首页</title>
    <jsp:include page="/zheng-admin-plugins/plugins/inc/head.jsp" flush="true"/>
</head>
<body>
<div id="main">
    <div id="toolbar">
        <shiro:hasPermission name="upms:user:create"><a id="1" class="waves-effect waves-button" href="javascript:;" onclick="searchDialogAction(this.id)"><i class="glyphicon glyphicon-search"></i>&nbsp 查询</a></shiro:hasPermission>
        <%--<shiro:hasPermission name="upms:user:update"><a id="2" class="waves-effect waves-button" href="javascript:;" onclick="searchDialogAction(this.id)"><i class="zmdi zmdi-edit"></i> 年度</a></shiro:hasPermission>
        <shiro:hasPermission name="upms:user:delete"><a id="3" class="waves-effect waves-button" href="javascript:;" onclick="searchDialogAction(this.id)"><i class="zmdi zmdi-close"></i> 保管期限</a></shiro:hasPermission>
        <shiro:hasPermission name="upms:user:organization"><a id="4" class="waves-effect waves-button" href="javascript:;" onclick="searchDialogAction(this.id)"><i class="zmdi zmdi-accounts-list"></i> 密级</a></shiro:hasPermission>
        <shiro:hasPermission name="upms:user:role"><a id="5" class="waves-effect waves-button" href="javascript:;" onclick="searchDialogAction(this.id)"><i class="zmdi zmdi-accounts"></i> 归档时间</a></shiro:hasPermission>--%>
        <div class="modal fade" id="searchDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="searchDialogTitle"></h4>
                    </div>
                    <div class="modal-body">
                        <form id="createForm" method="post">
                            <div class="form-group">
                                <%--<label for="VOL_ARCHIVE_UNIT">归档单位</label>--%>
                               <%-- <input id="VOL_ARCHIVE_UNIT" type="text" class="form-control" name="VOL_ARCHIVE_UNIT" maxlength="20">--%>
                                <select id="VOL_ARCHIVE_UNIT" name="VOL_ARCHIVE_UNIT"  style="width: 100%">//多选加上multiple="multiple"属性，单选无此属性
                                    <option></option>
                                    <c:forEach var="upmsOrganization" items="${upmsOrganizations}">
                                        <option value="${upmsOrganization.organizationId}">${upmsOrganization.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="form-group">
                               <%-- <label for="VOL_STORAGE_TIME">保管期限（例：10年/30年/永久）</label>--%>
                               <%-- <input id="VOL_STORAGE_TIME" type="text" class="form-control" name="VOL_STORAGE_TIME" maxlength="20">--%>
                                <select id="VOL_STORAGE_TIME" name="VOL_STORAGE_TIME"  style="width: 100%">//多选加上multiple="multiple"属性，单选无此属性
                                    <option></option>
                                    <c:forEach var="storagetime" items="${storagetime}">
                                        <option value="${storagetime.code}">${storagetime.description}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="form-group">
                                <%--<label for="VOL_SECRET">密级</label>--%>
                                <%--<input id="VOL_SECRET" type="text" class="form-control" name="VOL_SECRET" maxlength="20">--%>
                                <select id="VOL_SECRET" name="VOL_SECRET"  style="width: 100%">//多选加上multiple="multiple"属性，单选无此属性
                                    <option></option>
                                    <c:forEach var="secretlevel" items="${secretlevel}">
                                        <option value="${secretlevel.code}">${secretlevel.description}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="VOL_ARCHIVE_YEAR">年度（例：2016）</label>
                                <input id="VOL_ARCHIVE_YEAR" type="text" class="form-control" name="VOL_ARCHIVE_YEAR" maxlength="32">
                            </div>
                            <div class="form-group">
                                <label for="starttime">归档时间（起始时间）</label>
                               <input style="background-color: #FFFFFF" type="text"id="starttime" readonly="readonly" class="form-control" name="starttime" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'endtime\')||\'%y-%M-%d\'}',dateFmt:'yyyy-MM-dd'})" maxlength="50"/>
                            </div>
                            <div class="form-group">
                                <label for="endtime">归档时间（截止时间）</label>
                                <input style="background-color: #FFFFFF" type="text" id="endtime" readonly="readonly" class="form-control" name="endTime"onFocus="WdatePicker({minDate:'#F{$dp.$D(\'starttime\')}',maxDate: '%y-%M-%d',dateFmt:'yyyy-MM-dd'})" maxlength="50"/>
                            </div>
                            <div class="form-group text-right dialog-buttons">
                                <%-- <a class="waves-effect waves-button" href="javascript:;"></a>
                                 <a class="waves-effect waves-button" href="javascript:;" onclick="searchDialog.close();"></a>--%>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary"  onclick="querySubmit();">查询</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
    </div>
    <table id="table"></table>

</div>
<script src="${basePath}/zheng-admin-plugins/plugins/My97DatePicker/WdatePicker.js"></script>
<%--<script src="${basePath}/js/common.js"></script>--%>
<jsp:include page="/zheng-admin-plugins/plugins/inc/footer.jsp" flush="true"/>
<script>
    var $table = $('#table');
    var sign;
    var orgList={};
    $(function() {
        sign="0";
        // bootstrap table初始化
        $table.bootstrapTable({
            url: '${basePath}/manage/archiveDetailStatistics/detailStatistics',
            queryParams:queryParams,
            striped: true,
           // search: true,
            showRefresh: true,
            showColumns: true,
            minimumCountColumns: 2,
            clickToSelect: true,
            detailView: true,
            detailFormatter: 'detailFormatter',
            pagination: true,
            paginationLoop: false,
            sidePagination: 'server',
            silentSort: false,
            smartDisplay: false,
            escape: true,
            searchOnEnterKey: true,
            idField: 'userId',
            maintainSelected: true,
            toolbar: '#toolbar',
            showFooter: true,
            columns: [
                {field: 'ck', checkbox: true},
                {field: 'VOLNUM', visible:false},
                {field: 'VOL_NO', title: '案卷号', sortable: true, align: 'center'},
                {field: 'VOL_TITLE', title: '案卷标题',
                    footerFormatter: function(value){
                        return "合计";
                    }},
                {field: 'VOL_STORAGE_TIME', title: '保管期限',formatter: 'storageTimeFormatter'},
                {field: 'VOL_ITEM_NUMBER', title: '案卷件数', align: 'center'},
                {field: 'PAGENUM', title: '卷内页数',
                    footerFormatter: function(value){
                        return "案卷总数";
                    }},
                {field: 'VOL_AUDIT_LEADER', title: '审计组长',
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            if(value[i].VOLNUM==""||value[i].VOLNUM==null){
                                continue
                            }
                            sum += parseInt(value[i].VOLNUM);
                        }
                        return sum;
                    }},
                {field: 'VOL_AUDIT_DATE', title: '审计起止时间',
                    footerFormatter: function(value){
                        return "总件数";
                    }},
                {field: 'VOL_INSIDE_DATE', title: '卷内起止时间', sortable: true, align: 'center',
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            if(value[i].VOL_ITEM_NUMBER==""||value[i].VOL_ITEM_NUMBER==null){
                                continue
                            }
                            sum += parseInt(value[i].VOL_ITEM_NUMBER);
                        }
                        return sum;
                    }},
                {field: 'VOL_ARCHIVE_YEAR', title: '所属年度', align: 'center',
                    footerFormatter: function(value){
                        return "总页数";
                    }},
                {field: 'VOL_SECRET',formatter: 'secretFormatter', title: '密级',
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            if(value[i].PAGENUM==""||value[i].PAGENUM==null){
                                continue
                            }
                            sum += parseInt(value[i].PAGENUM);
                        }
                        return sum;
                    }},
                {field: 'VOL_ARCHIVE_UNIT', title: '归档单位',formatter: 'orgIdConversionNameFormatter'},
            ],
            onPostBody:function () {
                //合并页脚
                merge_footer();
            },
            onLoadSuccess:function(data){
                //无数据隐藏分页
                if(data && data.total == 0){
                    $('.fixed-table-pagination').hide()
                }
            }
        });
        initMaterialInput();
        $('#VOL_ARCHIVE_UNIT').select2({
            placeholder: '请选择归档单位',
            allowClear: true
        });
        $('#VOL_STORAGE_TIME').select2({
            placeholder: '请选择保管期限',
            allowClear: true
        });
        $('#VOL_SECRET').select2({
            placeholder: '请选择密级',
            allowClear: true
        });

        $.ajax({
            type: "POST",
            url: BASE_PATH + "/manage/organization/findAllOrgList",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.length != 0) {
                    var orgData = data.rows;
                    for (var i = 0; i < orgData.length; i++) {
                        var orgName = orgData[i].name;
                        var orgId = orgData[i].organizationId;
                        orgList[orgId] = orgName;
                    }
                }
            }
        });
    });

    //格式化归档单位
    function orgIdConversionNameFormatter(value, row, index){
        return orgList[value];
    }

    //保管期限格式化
    function storageTimeFormatter(value, row, index) {
        if (value == 1) {
            return '永久';
        }
        if (value == 2) {
            return '长期';
        }
        if (value == 3) {
            return '短期';
        }
        return '-';
    }

    //密级格式化
    function secretFormatter(value, row, index){
        if (value == 'MM') {
            return '秘密';
        }
        if (value == 'JM') {
            return '机密';
        }
        if (value == 'JU') {
            return '绝密';
        }
        return '-';
    }
    // 搜索弹窗
    function searchDialogAction(flag) {
        sign=flag;
        $("#searchDialogTitle").html("查询");
        $("#searchDialog").modal("show");

    }

    //获取搜索数据
    function querySubmit() {
        $table.bootstrapTable('refresh');
        $("#searchDialog").modal("hide");
    }
    //搜索传递参数
    function queryParams(params) {
        //这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
        var temp = {
            limit: params.limit,   //页面大小
            offset: params.offset,  //页码
            VOL_ARCHIVE_UNIT:$("#VOL_ARCHIVE_UNIT").val(),
            VOL_ARCHIVE_YEAR:$("#VOL_ARCHIVE_YEAR").val(),
            VOL_STORAGE_TIME:$("#VOL_STORAGE_TIME").val(),
            VOL_SECRET:$("#VOL_SECRET").val(),
            starttime:$("#starttime").val(),
            endtime:$("#endtime").val(),
            flag:sign,
        };
        return temp;
    }
    //合并页脚
    function merge_footer() {
        //获取table表中footer 并获取到这一行的所有列
        var footer_tbody = $('.fixed-table-footer table tbody');
        var footer_tr = footer_tbody.find('>tr');
        var footer_td = footer_tr.find('>td');
        var footer_td_1 = footer_td.eq(3);
        footer_td.eq(0).hide();
        footer_td.eq(1).hide();
        footer_td.eq(2).hide();
        footer_td.eq(4).hide();
        footer_td.eq(12).hide();
        footer_td_1.attr('colspan', footer_td.length-8).show();
        footer_td_1.attr('width', "428px").show();
        var footer_td_2 = footer_td.eq(5);
        footer_td.eq(5).hide();

    }

    function refreshButton() {
        sign="0";
        $table.bootstrapTable('refresh');
    }
</script>
</body>
</html>